Per series roll period#811
Per series roll period#811evamedia wants to merge 7 commits intodanvk:masterfrom evamedia:per-series-roll-period
Conversation
Enables adding of rollPeriod inside series parameters. If rollPeriod is set globally, series will default to that if parameter not set
|
Thanks for the contribution! To be considered for merging, this needs unit tests and needs to follow the style of the rest of the dygraphs code. |
|
You can absolutely update per-series options. Here's a demo:
http://jsfiddle.net/eM2Mg/9155/
…On Thu, Dec 29, 2016 at 4:37 AM, evamedia ***@***.***> wrote:
Looking into unit tests, can you currently change per-series options with
updateOptions() ?
Limited testing seems to say no, I also found this
// TODO(danvk): validate per-series options.
// Supported:
// strokeWidth
// pointSize
// drawPoints
// highlightCircleSize
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#811 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAF__fLLt58GIrXcmeCM0181VECUNhIvks5rM39XgaJpZM4LVZD1>
.
|
Test’s setting of per series rollPeriod in initial setup, then changing, and adding to another series. Tests series defaults to global rollPeriod if not explicitly set
|
apologies, auto_test submitted, can you give me a pointer on the style? Is there a guide? |
Shows two series and demonstrates independent changing of rolling average
danvk
left a comment
There was a problem hiding this comment.
This is looking good. I'd like one of the behaviors to be different, but other than that it's just style nits and cleanup. Thanks for adding the tests!
|
|
||
| var seriesOpt = {}; | ||
| seriesOpt["Y"] = { rollPeriod: 2 }; | ||
| g.updateOptions ({ series: seriesOpt }); |
There was a problem hiding this comment.
Make the updateOptions calls self-contained by writing them as:
g.updateOptions({
series: { Y: { rollPeriod: 2 } }
});and killing the seriesOpt variable (here and below).
| g.setSelection(3); assert.equal("3: Y: 3 Z: 15", Util.getLegend()); | ||
| assert.equal(1, g.getOption("rollPeriod", "Y")); | ||
| assert.equal(4, g.getOption("rollPeriod", "Z")); | ||
|
|
There was a problem hiding this comment.
style nit: remove these blank lines
| height: 320, | ||
| rollPeriod: 2, | ||
| series: { | ||
| Y: { |
| g.setSelection(2); assert.equal("2: Y: 1 Z: 10", Util.getLegend()); | ||
| g.setSelection(3); assert.equal("3: Y: 2 Z: 20", Util.getLegend()); | ||
| assert.equal(3, g.getOption("rollPeriod", "Y")); | ||
| assert.equal(3, g.getOption("rollPeriod", "Z")); |
There was a problem hiding this comment.
This should be 2 to be consistent with how other per-series options work. See http://jsfiddle.net/eM2Mg/9158/
There was a problem hiding this comment.
Not sure I understand "Y" is 3 because it was set previously, "Z" is 3 because the global rollPeriod was updated and "Z" hadn't been set separately. On the example initial strokeWidth : 4 for "Z" then the global StrokeWidth is changed to 1 , leaving "X" at 2
There was a problem hiding this comment.
Ah, nevermind. I misread this.
Could you add a test that makes sure updating the global rollPeriod doesn't affect a per-series rollPeriod?
src/dygraph.js
Outdated
| if (this.rollPeriod_ > 1) { | ||
| series = this.dataHandler_.rollingAverage(series, this.rollPeriod_, this.attributes_); | ||
| var seriesRollPeriod; | ||
|
|
There was a problem hiding this comment.
style nit: remove blank line & fix indentation
| </style> | ||
| </head> | ||
| <body> | ||
|
|
There was a problem hiding this comment.
style nit: use a two space indent in this file
src/dygraph.js
Outdated
| var seriesRollPeriod; | ||
|
|
||
| if (this.getOption('rollPeriod', seriesName[i])) { | ||
| seriesRollPeriod = this.getOption('rollPeriod', seriesName[i]); |
There was a problem hiding this comment.
It should suffice to say:
const rollPeriod = this.getOption('rollPeriod', seriesName[i]);this will get the per-series value or fall back to the global one.
| g.setSelection(3); assert.equal("3: Y: 3 Z: 25", Util.getLegend()); | ||
| assert.equal(1, g.getOption("rollPeriod", "Y")); | ||
| assert.equal(2, g.getOption("rollPeriod", "Z")); | ||
| assert.equal(2, g.rollPeriod()); |
There was a problem hiding this comment.
We should get rid of the rollPeriod() method. getOption('rollPeriod') does the same thing but also lets you get per-series values.
| for (var i = 1; i < this.numColumns(); i++) { | ||
| // var logScale = this.attr_('logscale', i); // TODO(klausw): this looks wrong // konigsberg thinks so too. | ||
| var series = this.dataHandler_.extractSeries(this.rawData_, i, this.attributes_); | ||
| if (this.rollPeriod_ > 1) { |
There was a problem hiding this comment.
Can you get rid of the rollPeriod_ member variable altogether?
There was a problem hiding this comment.
Do you mean the whole library?
Altered last test to prove changing global rollPeriod doesn’t change a series rollPeriod
|
Any idea if/when this functionality gets into the software? Currently I add it manally on each Dygraph release. |
Enables adding of rollPeriod inside series parameters. If rollPeriod is
set globally, series will default to that if parameter not set